<?php include('scripts.php'); ?>
<script type="text/javascript">
$(function() {
    $(".activeLink").click(function(event){
        event.preventDefault();
        $("#dgActivateMember").dialog("open");
        $("#distributorId").val($(this).attr("ref"));
        $("#dgActivateMember_shareholderId").val($(this).attr("refCode"));
        $("#dgActivateMember_alias").val($(this).attr("refNickname"));
        $("#dgActivateMember_registeredTime").val($(this).attr("refCreatedDate"));
        $("#dgActivateMember_pinAvail").val(<?php echo $pin; ?>);
    });

    $("#dgActivateMember").dialog("destroy");
    $("#dgActivateMember").dialog({
        autoOpen : false,
        modal : true,
        resizable : false,
        hide: 'clip',
        show: 'slide',
        width: 400,
        buttons: {
            "<?php echo __('Cancel') ?>": function() {
                $(this).dialog('close');
            },
            "<?php echo __('Submit') ?>": function() {
                if ($("#dgActivateMember_pin").val() == 0) {
                    alert("Pin cannot be zero.");
                    $("#dgActivateMember_pin").focus().select();
                } else if (parseFloat($("#dgActivateMember_pin").val()) > parseFloat(<?php echo $pin; ?>)){
                    alert("In-sufficient pin."+<?php echo $pin; ?>);
                    $("#dgActivateMember_pin").focus().select();
                } else {
                    if ($.trim($("#dgActivateMember_transactionPassword").val()) == "") {
                        alert("Transaction Password is empty");
                        $("#dgActivateMember_transactionPassword").focus();
                        return false;
                    }

                    $.ajax({
                        type : 'POST',
                        url : "/member/verifyTransactionPassword",
                        dataType : 'json',
                        cache: false,
                        data: {
                            transactionPassword : $('#dgActivateMember_transactionPassword').val()
                        },
                        success : function(data) {
                            if (data) {
                                $("#pin").val($("#dgActivateMember_pin").val());
                                $("#memberForm").attr("action", '/member/activateMember');
                                $("#memberForm").submit();
                            } else {
                                alert("Invalid Transaction Password");
                                $("#dgActivateMember_transactionPassword").focus().select();
                            }
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                            alert("Your login attempt was not successful. Please try again.");
                        }
                    });
                }
            }
        },
        open: function() {
            $("#dgActivateMember_pin").val("0");
        },
        close: function() {

        }
    });

    /*$("#dgActivateMember_pin").numeric({
        decimal:false
        , minValue:0
        , maxValue:<?php echo $pin; ?>
    });*/

    $("#dgReinvestCps_pinRequired").numeric({
        decimal:false
        , minValue:0
        , maxValue:<?php echo $pin; ?>
    });

    $("#dgReinvestCps").dialog("destroy");
    $("#dgReinvestCps").dialog({
        autoOpen : false,
        modal : true,
        resizable : false,
        hide: 'clip',
        show: 'slide',
        width: 400,
        buttons: {
            "<?php echo __('Cancel') ?>": function() {
                $(this).dialog('close');
            },
            "<?php echo __('Submit') ?>": function() {
                if ($.trim($("#dgReinvestCps_transactionPassword").val()) == "") {
                    alert("Transaction Password is empty");
                    $("#dgReinvestCps_transactionPassword").focus();
                    return false;
                }

                if ($("#dgReinvestCps_pinRequired").val() == 0) {
                    alert("Pin cannot be zero.");
                    $("#dgReinvestCps_pinRequired").focus().select();
                } else if (parseFloat($("#dgReinvestCps_pinRequired").val()) > parseFloat(<?php echo $pin; ?>)){
                    alert("In-sufficient pin."+<?php echo $pin; ?>);
                    $("#dgReinvestCps_pinRequired").focus().select();
                } else {
                    $.ajax({
                        type : 'POST',
                        url : "/member/verifyTransactionPassword",
                        dataType : 'json',
                        cache: false,
                        data: {
                            transactionPassword : $('#dgReinvestCps_transactionPassword').val()
                        },
                        success : function(data) {
                            if (data) {
                                $("#pin").val($("#dgReinvestCps_pinRequired").val());
                                $("#memberForm").attr("action", '/member/doGapInvest');
                                $("#memberForm").submit();
                            } else {
                                alert("Invalid Transaction Password");
                                $("#dgReinvestCps_transactionPassword").focus().select();
                            }
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                            alert("Your login attempt was not successful. Please try again.");
                        }
                    });
                }
            }
        },
        open: function() {
            $("#dgReinvestCps_pinRequired").val("0");
        },
        close: function() {

        }
    });

    $("#dgAnnouncement").dialog("destroy");
    $("#dgAnnouncement").dialog({
        autoOpen : false,
        modal : true,
        resizable : false,
        hide: 'clip',
        show: 'slide',
        width: 700,
        height: 500,
        buttons: {
            "<?php echo __('Cancel') ?>": function() {
                $(this).dialog('close');
            }
        },
        open: function() {
            $.ajax({
                type : 'POST',
                url : "/member/fetchAnnouncementById",
                dataType : 'json',
                cache: false,
                data: {
                    announcementId : $('#dgAnnouncement').data("refId")
                },
                success : function(data) {
                    $("#tdAnnouncement").html(data.content);
                    $("#dgAnnouncement").dialog("option", "title", data.title);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("Your login attempt was not successful. Please try again.");
                }
            });
        },
        close: function() {

        }
    });

    $("#reinvestGapLink").live("click", function(event) {
        event.preventDefault();
        $("#dgReinvestCps").dialog("open");
    });
    $(".announcementLink").live("click", function(event) {
        event.preventDefault();
        $("#dgAnnouncement").data("refId", $(this).attr("refId")).dialog("open");
    });
});
</script>

<form action="/member/activateMember" method="post" id="memberForm">
<input type="hidden" name="distributorId" id="distributorId">
<input type="hidden" name="pin" id="pin">
<table cellpadding="0" cellspacing="5" align="center" border="0" width='100%'>
    <tr>
        <td>
			<table border='1' width='100%'>
			<tr valign="middle" style="background-color:#f1f1f1;height:32px;">
				<td colspan=6 align='center'><?php echo __('Account Details') ?></td>
			</tr>
			<tr valign="middle" style="background-color:#f1f1f1;height:32px;">
				<td align='center'><?php echo __('CPS') ?></td><td align='center'><?php echo __('Dividend (g)') ?></td><td align='center'><?php echo __('Pin') ?></td><td align='center'><?php echo __('E-Cash') ?></td><td align='center'><?php echo __('Trading Margin') ?></td><td align='center'><?php echo __('GAP') ?></td>
			</tr>
			<tr style="background:#ccc;" onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f1f1f1';" onmouseout="this.style.backgroundColor=currentcolor" style="height:25px;">
				<td align='center'><?php echo number_format($cps,2); ?></td><td align='center'><?php echo number_format($gold,2); ?></td><td align='center'><?php echo $pin; ?></td><td align='center'><?php echo number_format($ecash,2); ?></td><td align='center'><?php echo number_format($trading,2); ?></td>
                <td align='center'><?php
                    if ($displayReinvestGapLink) {
                        echo "<a href='#' id='reinvestGapLink'>".number_format($gap,2)."</a>";
                    } else
                        echo number_format($gap,2);
                ?></td>
			</tr>
			</table>
		</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td>
			<table border='1' width='100%'>
			<tr valign="middle" style="background-color:#f1f1f1;height:32px;">
				<td colspan=5 align='center'><?php echo __('Inactive Shareholders') ?></td>
			</tr>
			<tr valign="middle" style="background-color:#f1f1f1;height:32px;">
				<td align='center'><?php echo __('Shareholder ID') ?></td><td align='center'><?php echo __('Alias') ?></td><td align='center'><?php echo __('Registered Time') ?></td><td align='center'><?php echo __('Activate') ?></td><td align='center'><?php echo __('Delete') ?></td>
			</tr>
			<?php			
			foreach($TblDistributor as $dist){
				echo "<tr style=\"background:#ccc;\" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f1f1f1';\" onmouseout=\"this.style.backgroundColor=currentcolor\" style=\"height:25px;\"><td align='center'>".$dist->getFCode()."</td><td align='center'>".$dist->getFNickname()."</td>
				      <td align='center'>".$dist->getFCreatedDatetime()."</td>
				      <td align='center'>".link_to(__('Active'), '#', array (
                          'class' => 'activeLink',
                          'ref' => $dist->getFId(),
                          'refCode' => $dist->getFCode(),
                          'refNickname' => $dist->getFNickname(),
                          'refCreatedDate' => $dist->getFCreatedDatetime(),
                        ))."</td>
				      <td align='center'>".link_to(__('Delete'), 'member/delete?distid='.$dist->getFId(), 'confirm=Are you sure you want to remove?')."</td></tr>";
			}			
			?>
			</table>
		</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td>
            <table border='1' width='100%'>
                <tr valign="middle" style="background-color:#f1f1f1;height:32px;">
                    <td align='center'><?php echo __('Title') ?></td><td align='center'><?php echo __('Date') ?></td>
                </tr>
                <?php
                    foreach($TblAnnoucement as $annoucement){
                        echo "<tr style=\"background:#ccc;\" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f1f1f1';\" onmouseout=\"this.style.backgroundColor=currentcolor\" style=\"height:25px;\"><td align='center'>".link_to($sf_user->getCulture()=="en"?$annoucement->getFTitle():$annoucement->getFTitleCn(), '/member/viewAnnoucement?id='.$annoucement->getFId(), array (
                          'class' => 'announcementLink', 'refId' => $annoucement->getFId()
                        ))."</td><td align='center'>".$annoucement->getFCreatedDatetime()."</td></tr>";
                    }
                ?>
            </table>
        </td>
    </tr>
</table>
</form>
<div id="dgActivateMember" title="<?php echo __('Activate Shareholder') ?>" style="display:none;">
    <table cellspacing="5">
        <tr>
            <td class="text"><label><?php echo __('Shareholder ID') ?></label></td>
            <td>:</td>
            <td><input type="text" disabled="disabled" id="dgActivateMember_shareholderId" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('Alias') ?></label></td>
            <td>:</td>
            <td><input type="text" disabled="disabled" id="dgActivateMember_alias" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('Registered Time') ?></label></td>
            <td>:</td>
            <td><input type="text" disabled="disabled" id="dgActivateMember_registeredTime" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('PIN Available') ?></label></td>
            <td>:</td>
            <td><input type="text" disabled="disabled" id="dgActivateMember_pinAvail" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('PIN Used to Activate') ?></label></td>
            <td>:</td>
            <td>
                <!--<input type="text" id="dgActivateMember_pin" class="text ui-widget-content ui-corner-all"/>-->
                <select name="dgActivateMember_pin" id="dgActivateMember_pin" class='text ui-widget-content ui-corner-all'>
                    <?php
                        foreach($arrs as $arr)
                            echo "<option value='".$arr."'>".$arr."</option>";
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('Transaction Password') ?></label></td>
            <td>:</td>
            <td><input type="password" id="dgActivateMember_transactionPassword" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
    </table>
</div>
<div id="dgReinvestCps" title="Reinvest CPS" style="display:none;">
    <table cellspacing="5">
        <tr>
            <td class="text"><label><?php echo __('PIN Available') ?></label></td>
            <td>:</td>
            <td><input type="text" disabled="disabled" id="dgReinvestCps_pinAvail" value="<?php echo $pin; ?>" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('No. of PIN required') ?></label></td>
            <td>:</td>
            <td><input type="text" id="dgReinvestCps_pinRequired" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
        <tr>
            <td class="text"><label><?php echo __('Transaction Password') ?></label></td>
            <td>:</td>
            <td><input type="password" id="dgReinvestCps_transactionPassword" class="text ui-widget-content ui-corner-all"/></td>
        </tr>
    </table>
</div>
<div id="dgAnnouncement" title="<?php echo __('Announcement') ?>" style="display:none;">
    <table cellspacing="5">
        <tr>
            <td class="text" id="tdAnnouncement"></td>
    </table>
</div>